home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MATH.SWG / 0025_Dividing Fixed Integers.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  1KB  |  70 lines

  1. {
  2. SEAN PALMER
  3.  
  4. I'm using TP. Here are the fixed division routines I'm currently using
  5. (they are, as you can see, quite specialized)
  6.  
  7. I had to abandon the original fixed division routines because I didn't
  8. know how to translate the 386-specific instructions using DB. (MOVSX,
  9. SHLD, etc)
  10. }
  11.  
  12. type
  13.   fixed = record
  14.     f : word;
  15.     i : integer;
  16.   end;
  17.  
  18.   shortFixed = record
  19.     f : byte;
  20.     i : shortint;
  21.   end;
  22.  
  23. { this one divides a fixed by a fixed, result is fixed needs 386 }
  24.  
  25. function fixedDiv(d1, d2 : longint) : longint; assembler;
  26. asm
  27.   db $66; xor dx, dx
  28.   mov cx, word ptr D1 + 2
  29.   or cx, cx
  30.   jns @S
  31.   db $66; dec dx
  32.  @S:
  33.   mov dx, cx
  34.   mov ax, word ptr D1
  35.   db $66; shl ax, 16
  36.   db $66; idiv word ptr d2
  37.   db $66; mov dx, ax
  38.   db $66; shr dx, 16
  39. end;
  40.  
  41. { this one divides a longint by a longint, result is fixed needs 386 }
  42.  
  43. function div2Fixed(d1, d2 : longint) : longint; assembler;
  44. asm
  45.   db $66; xor dx, dx
  46.   db $66; mov ax, word ptr d1
  47.   db $66; shl ax, 16
  48.   jns @S;
  49.   db $66; dec dx
  50.  @S:
  51.   db $66; idiv word ptr d2
  52.   db $66; mov dx, ax
  53.   db $66; shr dx, 16
  54. end;
  55.  
  56. { this one divides an integer by and integer, result is shortFixed }
  57.  
  58. function divfix(d1, d2 : integer) : integer; assembler;
  59. asm
  60.   mov al, byte
  61.   ptr d1 + 1
  62.   cbw
  63.   mov dx, ax
  64.   xor al, al
  65.   mov ah, byte ptr d1
  66.   idiv d2
  67. end;
  68.  
  69.  
  70.